package com.terrace.core.jackson.databind;

import java.io.IOException;
import java.util.Date;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.terrace.core.utils.DateUtils;

/**
 * Date转为yyyy-MM-dd HH:mm:ss格式的字符串
 * @author jiangyg
 *
 */
public class DateTimeFormaterSerializer extends JsonSerializer<Date> {
	
	@Override
	public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
			throws IOException, JsonProcessingException {
		String dateStr = DateUtils.DATETIME_FORMATER.format(value);
		jgen.writeString(dateStr);
	}

}
